#ifndef MAINSCENE_H
#define MAINSCENE_H

#include <QGraphicsScene>
#include "circuitcomponent.h"
#include "wireitem.h"
#include "voltagemeteritem.h"
#include "relayitem.h"

#define MainSceneIns MainScene::Instance()

class MainScene : public QGraphicsScene
{
    Q_OBJECT
public:
    explicit MainScene(QObject *parent = nullptr);

    static MainScene *Instance();

public:
    void SetVolterB(double value);
    void SetVolterP(double value);
    void SetEnableRelay(bool relayEnable);
    void SetFSState(bool state);
    QByteArray GetCurrentByte();
    void SetByte(const QByteArray &canData);

private:
    void setupCircuit();
    void createWire(QGraphicsItem *startItem, CircuitComponent::PortType startPortType,
                    QGraphicsItem *endItem, CircuitComponent::PortType endPortType);

    QColor validateConnection(CircuitComponent::PortType start, CircuitComponent::PortType end);

private:
    QList<Wire*>m_wires;    
    QList<Relay*>m_relays;
    VoltageMeter *m_vmb;
    VoltageMeter *m_vmp;
    QByteArray m_canData;

    Relay *relay;
    Relay *relay_1;
    Relay *relay_2;
    Relay *relay_main_;
    Relay *relay_14;

private slots:
    void on_changeState_MainZ(bool state);
    void on_changeState_MainF(bool state);
    void on_changeState_FastC(bool state);
    void on_changeState_PrevC(bool state);

Q_SIGNALS:
    void sendData(int ID,const QByteArray &data);
};

#endif // MAINSCENE_H
